home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / gdata / tlslite / SharedKeyDB.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.8 KB  |  69 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Class for storing shared keys.'''
  5. from utils.cryptomath import *
  6. from utils.compat import *
  7. from mathtls import *
  8. from Session import Session
  9. from BaseDB import BaseDB
  10.  
  11. class SharedKeyDB(BaseDB):
  12.     '''This class represent an in-memory or on-disk database of shared
  13.     keys.
  14.  
  15.     A SharedKeyDB can be passed to a server handshake function to
  16.     authenticate a client based on one of the shared keys.
  17.  
  18.     This class is thread-safe.
  19.     '''
  20.     
  21.     def __init__(self, filename = None):
  22.         '''Create a new SharedKeyDB.
  23.  
  24.         @type filename: str
  25.         @param filename: Filename for an on-disk database, or None for
  26.         an in-memory database.  If the filename already exists, follow
  27.         this with a call to open().  To create a new on-disk database,
  28.         follow this with a call to create().
  29.         '''
  30.         BaseDB.__init__(self, filename, 'shared key')
  31.  
  32.     
  33.     def _getItem(self, username, valueStr):
  34.         session = Session()
  35.         session._createSharedKey(username, valueStr)
  36.         return session
  37.  
  38.     
  39.     def __setitem__(self, username, sharedKey):
  40.         '''Add a shared key to the database.
  41.  
  42.         @type username: str
  43.         @param username: The username to associate the shared key with.
  44.         Must be less than or equal to 16 characters in length, and must
  45.         not already be in the database.
  46.  
  47.         @type sharedKey: str
  48.         @param sharedKey: The shared key to add.  Must be less than 48
  49.         characters in length.
  50.         '''
  51.         BaseDB.__setitem__(self, username, sharedKey)
  52.  
  53.     
  54.     def _setItem(self, username, value):
  55.         if len(username) > 16:
  56.             raise ValueError('username too long')
  57.         len(username) > 16
  58.         if len(value) >= 48:
  59.             raise ValueError('shared key too long')
  60.         len(value) >= 48
  61.         return value
  62.  
  63.     
  64.     def _checkItem(self, value, username, param):
  65.         newSession = self._getItem(username, param)
  66.         return value.masterSecret == newSession.masterSecret
  67.  
  68.  
  69.